<?php

class DBConnect {
	private $mysql_connect;
	private $host;
	private $user;
	private $pass;
	private $dbname;
	private $encoding;
	
	function __construct ($host, $user, $pass, $dbname, $encoding = "utf8") {
		$this->host = $host;
		$this->user = $user;
		$this->pass = $pass;
		$this->dbname = $dbname;
		$this->encoding = $encoding;
		$this->mysql_connect = null;
	}
	
	public function connect(){
		if (!$this->mysql_connect){
			$this->mysql_connect = @mysql_connect($this->host, $this->user, $this->pass);
			@mysql_select_db($this->dbname, $this->mysql_connect) or die ("Can't use DB: " . mysql_error());;
			mysql_query("SET NAMES $this->encoding");
		}
	}
	
	public function disconnect(){
		if ($this->mysql_connect){
			@mysql_close($this->mysql_connect);
			$this->mysql_connect = null;
		}
	}
}

?>
